//
//  DDHighLightCell.m
//  DingDongZP
//
//  Created by Jyh on 16/5/2.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDHighLightCell.h"
#import "SKTagView.h"

@interface DDHighLightCell ()

@property (strong, nonatomic) SKTagView *tagView;

@end


@implementation DDHighLightCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.detailView.layer.cornerRadius = 5;
    self.detailView.layer.borderColor = COLOR_BORDER_GRAY.CGColor;
    self.detailView.layer.borderWidth = 0.5;
    
    self.highLightLabel.text = @"";
}

- (void)updateHighlightInfoWith:(DDJobfinderDetailInfo *)detailInfo
{
    [self.highLightLabel removeFromSuperview];
    [self.contentView addSubview:self.highLightLabel];
    
    CGFloat cellHeight = 50;
    
    CGFloat textWidth = kScreenWidth - (10*2 + 12*2);
    CGFloat textHeight = [DDUtils heightWithWidth:textWidth font:[UIFont systemFontOfSize:12.f] text:detailInfo.mystrengthstext];
    
    cellHeight += textHeight;
    
    self.highLightLabel.text = detailInfo.mystrengthstext;
    
    WEAKSELF
    [self.highLightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.detailView.mas_top).offset(50);
        make.left.mas_equalTo(weakSelf.detailView.mas_left).offset(12);
        make.right.mas_equalTo(weakSelf.detailView.mas_right).offset(-12);
        make.height.mas_equalTo(textHeight);
    }];
    
    detailInfo.highlights = @[@"美女如云",@"五险一金",@"技术扎实"];
    
    if ([detailInfo.highlights count] > 0) {
        [self addTagWithInfoWithArray:[detailInfo.highlights mutableCopy]];
        
        [self.contentView addSubview:self.tagView];
        
        [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.detailView.mas_left);
            make.top.mas_equalTo(weakSelf.highLightLabel.mas_bottom).offset(10);
            make.bottom.mas_equalTo(weakSelf.detailView.mas_bottom);
            make.right.mas_equalTo(weakSelf.detailView.mas_right);
            make.height.mas_equalTo(100);
        }];
        
        cellHeight += 100;
    }
    
    cellHeight += 10;
    
    self.highLightCellHeight = cellHeight;
}

- (void)addTagWithInfoWithArray:(NSMutableArray *)tagArray
{
    //Add Tags
    if ([tagArray count] > 0) {
        [self.tagView removeAllSubviews];
        
        [tagArray enumerateObjectsUsingBlock:^(NSString *text, NSUInteger idx, BOOL * _Nonnull stop) {
            SKTag *tag = [SKTag tagWithText: text];
            tag.textColor = [UIColor whiteColor];
            tag.fontSize = 12;
            tag.padding = UIEdgeInsetsMake(5, 5, 5, 5);
            tag.cornerRadius = 2;
            tag.bgColor = COLOR_NAVIGATIONBAR;
            [self.tagView addTag:tag];
        }];
    }
}

- (SKTagView *)tagView {
    if (!_tagView) {
        _tagView = [SKTagView new];
        _tagView.backgroundColor = [UIColor whiteColor];
        _tagView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        _tagView.interitemSpacing = 10;
        _tagView.lineSpacing = 10;
    }
    
    return _tagView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
